package com.hna.face.bussiness;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hna.face.model.FaceVehicle;
import com.hna.face.service.IFaceVehicleService;

@Service
public class OnlineMessageHandler extends MessageHandler{

	private final static Logger log = LoggerFactory.getLogger(OnlineMessageHandler.class);

	@Autowired
	private IFaceVehicleService service;
	
	/*
	 * 修改上线信息
	 */
	@Override
	public void run() {
		if(message ==null)
		{
			return;
		}
		byte[] payload = message.getPayload();//获取二进制文件
	    String vehicleNo = new String(payload);//转成json对象
		log.info("payload:"+vehicleNo);
		vehicleNo = vehicleNo.substring(vehicleNo.indexOf("online"));
	    log.info("vehicleNo:"+vehicleNo);
		Wrapper<FaceVehicle> wraper = new EntityWrapper<>();
		wraper.eq("vehicle_no", vehicleNo);//按照车辆编号查找
		FaceVehicle faceVehicle=null;
		try {
			faceVehicle = service.selectOne(wraper);
		}catch(Exception e)
		{
			log.error("",e);
		}
		log.info("faceVehicle:"+faceVehicle);
		faceVehicle.setStatus(2);//修改上线
		boolean update = service.update(faceVehicle, wraper);//按照车辆编号修改
		log.info("willUpdate:"+update);
		
	}
}
